<?php

// An example callback function
function my_callback_function($par) {
    echo 'hello world! par=' . $par . PHP_EOL;
}

// An example callback method
class MyClass {
    static function myCallbackMethod($par) {
        echo 'Hello World! par=' . $par . PHP_EOL;
    }
}

// Type 1: Simple callback
call_user_func('my_callback_function', 1);

// Type 2: Static class method call
call_user_func(array('MyClass', 'myCallbackMethod'), 2);

// Type 3: Object method call
$obj = new MyClass();
call_user_func(array($obj, 'myCallbackMethod'), 3);

// Type 4: Static class method call (As of PHP 5.2.3)
call_user_func('MyClass::myCallbackMethod', 4);

// Type 5: Relative static class method call (As of PHP 5.3.0)
class A {
    public static function who() {
        echo "A\n";
    }
}

class B extends A {
    public static function who() {
        echo "B\n";
    }
}

call_user_func(array('B', 'parent::who')); // A
call_user_func(array('B', 'who')); // A

// Type 6: Objects implementing __invoke can be used as callables (since PHP 5.3)
class C {
    public function __invoke($name) {
        echo 'Hello ', $name, "\n";
    }
}

$c = new C();
call_user_func($c, 'PHP!');
?>
